package com.ptszyxx.popose.module.base.user.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.user.LabelItemEntity;
import com.ysg.http.data.entity.user.UserLabelResult;
import com.ysg.http.data.entity.user.UserResult;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YToastUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserResultVM extends BaseViewModel<CommonRepository> {
    public ObservableField<UserResult> userEntity = new ObservableField<>();

    public UserResultVM(@NonNull Application application, CommonRepository repository) {
        super(application, repository);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onTagEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onSubmitCommand = new BindingCommand(() -> onJumpMain());

    /**
     * 请求用户信息
     */
    public void requestUser(){
        Map<String, String> map = new HashMap<>();

        HttpUtils.getInstance()
                .data(model.user(map), this,
                        new OnSuccessResult<UserResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<UserResult> response) {
                                userEntity.set(response.getData());
                                uc.onTagEvent.call();
                            }
                        });
    }

    private void onJumpMain(){
        YActivityUtil.getInstance().jumpMainActivity(this, null);
        YSPUtils.getInstance().saveLogin(true);
    }



}
